from pms.common.views import PostFormula
from project.utils.member import project_delete_member
from project.utils.profile import member_view
from project.models import Project
from user.models import User
from project.utils.permission import assert_project_permissions


class API(PostFormula):

    def handle(self, req):
        uid = req['uid']
        pid = req['pid']
        assert_project_permissions(pid, self.user.id, [3])
        user = User.objects.get(id=uid)
        project = Project.objects.get(id=pid)
        view = member_view(project, user)
        project_delete_member(project, user)
        return self.success_respond(view)
